home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13032 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: news.uh.edu!cosc19z5
  2. From: cosc19z5@Bayou.UH.EDU (Spasmo)
  3. Newsgroups: comp.lang.c,comp.unix.programmer
  4. Subject: Re: Q: '\n' character
  5. Followup-To: comp.lang.c,comp.unix.programmer
  6. Date: 3 Apr 1996 08:38:21 GMT
  7. Organization: University of Houston
  8. Distribution: world
  9. Message-ID: <4jtddt$eu7@masala.cc.uh.edu>
  10. References: <31616F63.481D@lava.weeg.uiowa.edu>
  11. NNTP-Posting-Host: bayou.uh.edu
  12. X-Newsreader: TIN [version 1.2 PL2]
  13.  
  14. Artur Wojdat (awojdat@lava.weeg.uiowa.edu) wrote:
  15. : Hello everybody,
  16. :     Is there a function or some sort of way that I could remove '\n' 
  17. : charecter form the end of the string. I'm reading from two files, want to 
  18. : form one line of text and then have it printed out to stdout. I use fgets to 
  19. : read from the file and I noticed that it appends newline char at the end.
  20. :     It is important that two lines of text, one from each file, will be 
  21. : combined into one and I can't do it because the first string has '\n' added 
  22. : to it. I'm picky becauuse the output will be used to feed another program and 
  23. : I'm affraid that not properly formatted input may corrupt the process.
  24. :     Any suggestions will be greatly appreciated .. Thanks, Art ...
  25.  
  26. Dunno if there are any functions available, but what I always do
  27. is just overwrite the '\n' with a '\0', which does the job nicely.
  28.  
  29. For example, let's say that the string that holds the data is called
  30. buf.  To get rid of the '\n' you'd merely do the following:
  31.  
  32.     buf[strlen(buf) - 1] = '\0';
  33.  
  34. And that takes care of that.
  35.  
  36. Hope this helped.
  37.  
  38. --
  39.  
  40.                       .A.                        G-Force!  1 AM Houston Time
  41.                      AAAAA                       On the Cartoon Network!
  42.                     AAY:YAA   
  43.                     A':::`A                      This informative message was 
  44.                     :::::::                      brought to you by Spasmo.
  45.                     ::( )::   
  46.                     :::::::
  47.                     :::::::
  48.                     :::::::
  49.                     :::::::     
  50.   .A.          .do:::::::::::bo.          .A.
  51.   AAA       .:::::::::::::::::::::.       AAA
  52.  d:::::::::::::::::::::::::::::::::::::::::::b
  53.  Y:::::::::::::::::::::::::::::::::::::::::::Y 
  54.  `YjY       `:::::::|::|::|:::::::'       YjY' 
  55.                  `::|::|::|::'  
  56.                        |
  57.